//
//  oldNetWork.h
//  laonianbang
//
//  Created by 勇拓 李 on 17/10/9.
//  Copyright © 2017年 zaiyou. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "AFNetworking.h"
#import "NetWorkSettings.h"

typedef void ( ^ SuccessBlock ) ( id data);
typedef void ( ^ ErrorBlock )( NSString * error);
typedef void ( ^ DownBlock )( NSString * result_url);

#define OLDNetWork [oldNetWork shareInstance]

typedef NS_ENUM(NSInteger, SXNetLoginState) {
    UnLogined = 0,
    Logined,
    Logining,
};

typedef NS_ENUM(NSInteger, SXTokenUpdatingState) {
    Updating = 0,
    Updated
};

extern NSString *const SXTokenKey;

@protocol TokenErrorDelegate <NSObject>
- (void)gotoLoginViewController:(NSString *)errorCode;
@end

@interface oldNetWork : NSObject
@property (nonatomic, weak) id<TokenErrorDelegate> delegate;

+ ( instancetype ) shareInstance;

- ( void ) httpRequestWithGet : ( NSString * ) url
                       params : ( NSDictionary * ) params
                      success : ( SuccessBlock ) successBlock
                        error : ( ErrorBlock ) errorBlock;

- ( void ) httpRequestWithPostPut : ( NSString * ) url
                           params : ( NSDictionary * ) params
                          success : ( SuccessBlock ) successBlock
                            error : ( ErrorBlock ) errorBlock;

- (void)httpRequestWithGetHaveCache:(NSString *)url ifneedCache:(BOOL)ifneed params:(NSDictionary *)params premethod:(void (^)(NSDictionary *))premethod success:( SuccessBlock )successBlock error:(ErrorBlock) errorBlock;

- (void)httpRequestWithPostHaveCache:(NSString *)url ifneedCache:(BOOL)ifneed params:(NSDictionary *)params premethod:(void (^)(NSDictionary *))premethod success:( SuccessBlock )successBlock error:(ErrorBlock) errorBlock;

- (void)downloadFile:(NSString *)url filePath:(NSString *)filePath block:(DownBlock)block;

- (void)setAFHTTPSessionManagerToken:(NSString *)token;

- (void)tokenError:(NSString *)errorCode;

- (void)clearToken;

@property( nonatomic, readonly ) AFHTTPSessionManager * manager;
@property (nonatomic, copy)NSString *token;


@end
